/*
ID:luongho3
LANG:C++
TASK:heritage
*/
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("heritage.in");
ofstream fout("heritage.out");
string inorder,preorder,postorder;

string solve(string in, string pre) {
       if (in.length()<=0) return "";
       int i;
       string inleft, preleft, inright, preright, t1,t2;
       for (i=0;i<in.length();++i) {
           if (in[i] == pre[0]) {
              break;
           }
       }
       inleft = in.substr(0,i);
       inright = in.substr(i+1);
       preleft = pre.substr(1,i);
       preright = pre.substr(i+1);
       t1 = solve(inleft,preleft);
       t2 = solve(inright,preright);
       return t1 + t2 + pre[0];;
}
int main() {
    fin >> inorder;
    fin >> preorder;
    postorder = "";
    postorder = solve(inorder, preorder);
    fout << postorder << "\n";
    return 0;
}
